package com.manager.service;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.stereotype.Service;

import com.manager.pojo.User;

@Service
public class RedisService {
	@Resource(name="redisTemplate")
	RedisTemplate template;
     
	public void add(final User user){
	   	 template.execute(new RedisCallback<Boolean>() {

			public Boolean doInRedis(RedisConnection coon) throws DataAccessException {
				 RedisSerializer<String> serializer = template.getStringSerializer();
				 byte key[] = serializer.serialize(user.getUseranme());
				 byte value[] = serializer.serialize(user.getPassword());
   				 return coon.setNX(key, value);
			}
		});
		
	}
}
